package com.eps.core;

import org.hibernate.SessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationObjectSupport;

/**
 * 全局资源管理器
 * User: Red_Code
 * Date: 12-10-31
 * Time: 上午11:38
 */
public class EpsManager implements ApplicationContextAware {

    private static EpsManager epsManager;
    private static HibernateTemplate hibernateTemplate=null;
    private static ApplicationContext context=null;

    public EpsManager() {
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context=applicationContext;
    }

    public ApplicationContext getApplicationContext()
    {
        return this.context;
    }

    public static EpsManager getManager()
    {
        if (null == epsManager) {
            epsManager = new EpsManager();
        }
        return epsManager;
    }

    public Object getBean(String sBeanName)
    {
        try{
            return getApplicationContext().getBean(sBeanName);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    public SessionFactory getSessionFactory()
    {
        return (SessionFactory)getBean("sessionFactory");
    }

//    public HibernateTemplate GetHibernateTemplate()
//    {
//        if (null==hibernateTemplate)
//        {
//            hibernateTemplate=new HibernateTemplate(getSessionFactory());
//        }
//        return hibernateTemplate;
//    }
}
